package com.demo.game1;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

public class Evil {
	
	int x;
	int y;
	int xspeed;
	int xmv;
	int width;
	int height;
	int ROW = 4;
	int COL = 3;
	int currentColFrame = 0;
	int currentRowFrame;
	GameView gameview;
	Bitmap bmp;
	
	
	public Evil( GameView gameview, Bitmap bm)
	{
		this.gameview = gameview;
		this.bmp = bm;
		x = 0;		
		width = bm.getWidth()/COL;
		height = bm.getHeight()/ROW;
		y = gameview.getHeight() - height;
		xspeed = 5;
		currentRowFrame = 2;
	}
	
	public void moveLR()
	{
		x += xspeed;		
		if(x <= 0)
		{			
			xspeed = -xspeed;
			currentRowFrame = 2;
		}
		
		if(x + width >= gameview.getWidth())
		{			
			xspeed = -xspeed;
			currentRowFrame = 1;
		}				
				
		currentColFrame = ++currentColFrame % COL;
	}
	
	
	public boolean isCollison(int x2 , int y2 , int w2, int h2)
	{
		return (x2 >= x && x2+w2 <= x + width) && (y2+h2 >= y);
	}

	public void onDraw(Canvas canvas)
	{
		moveLR();
		  int srcX = currentColFrame * width;
          int srcY = currentRowFrame * height;
          Rect src = new Rect(srcX, srcY, srcX + width, srcY + height);
          Rect dst = new Rect(x, y, x + width, y + height);
		canvas.drawBitmap(bmp, src, dst, null);
	}
}
  